﻿// -------------------------------------------------------------------------
//    @FileName         :    NFOnlineAcc.h
//    @Author           :    gaoyi
//    @Date             :    2025-04-03
//    @Email			:    445267987@qq.com
//    @Module           :    NFOnlineAcc
//
// -------------------------------------------------------------------------

#pragma once

#include <proto_svr_onlinesvr.pb.h>

#include "proto_db.nanopb.h"
#include "NFComm/NFObjCommon/NFObject.h"
#include "NFLogicCommon/BagPage/NFBagPage.h"
#include "NFLogicCommon/NFCommDefine.h"
#include "NFLogicCommon/NFLogicShmTypeDefines.h"
#include "NFServerComm/NFServerCommon/NFCacheDataTemplate.h"

enum NfOnlineAccState
{
    ONLINE_ACC_NONE = 0, //None
    ONLINE_ACC_LOGIN = 1, //登录占位中
    ONLINE_ACC_ACTIVE = 2, //在线状态
    ONLINE_ACC_EXIT = 3, //注销中
};
class NFOnlineAcc : public NFCacheDataWithSaveDbTemplate<NFOnlineAcc, proto_ff::tbRoleList, tbRoleList, EOT_ONLINE_ACC_ID>
{
public:
    NFOnlineAcc();
    ~NFOnlineAcc() override;
    int CreateInit();
    int ResumeInit();
public:
    int InitData(const proto_ff::tbRoleList* pPbClass) override;
    int SaveData(proto_ff::tbRoleList* pPbClass) override;
    int OnTimer(int timeId, int callCount) override;
public:
    int SendTransToDb(int iReason) override;
    int GetCacheCreateTimeoutSec() const override { return std::numeric_limits<int>::max(); }
    int GetCacheExpireTimeSec() const override { return std::numeric_limits<int>::max(); }
public:
    bool CanDelete();
public:
    uint64_t GetUid() const { return m_uid; }
    void SetUid(uint64_t uid) { m_uid = uid; }
    int GetZoneId() const { return m_zoneId; }
    void SetZoneId(int zoneId) { m_zoneId = zoneId; }
    int GetState() const { return m_state; }
    void SetState(int state) { m_state = state; }
    bool HasInitRoleList() { return m_isInitRoleList == true; }
    void SetInitRoleList() { m_isInitRoleList = true; }
public:
    int GetLoginTransTime() const { return m_loginTransTime; }
    void SetLoginTransTime(int loginTransTime) { m_loginTransTime = loginTransTime; }
    int GetAddRoleLockTime() const { return m_addRoleLockTime; }
    void SetAddRoleLockTime(int addRoleLockTime) { m_addRoleLockTime = addRoleLockTime; }
public:
    tbRoleList* GetRoleList() { return &m_stData; }
    RoleData* GetRoleData() { return &m_stData.role_data; }
public:
    RoleOne* FindRoleOne(uint64_t ullRoleId);

    static RoleOne* FindRoleOne(uint64_t ullRoleId, RoleData& roleData);

    static RoleOne* FindDelRoleOne(uint64_t ullRoleId, RoleData& roleData);
public:
    int AddRole(RoleOne& stRoleOne);

    static int AddRole(RoleOne& stRoleOne, RoleData& roleData);

    bool HasRole(uint64_t ullRoleId);

    static bool HasRole(uint64_t ullRoleId, RoleData& roleData);

    static bool HasDelRole(uint64_t ullRoleId, RoleData& roleData);

    int DeleteRole(uint64_t ullRoleId);

    int AddDelRole(RoleOne& stRoleOne);

    bool IsDelRoleFull() { return m_stData.role_data.del_role.full(); }
public:
    int TryAccLogin(const proto_ff::Proto_Zone2OnLineLoginReq& req, int fromBusId, int transId);
    int GetRoleList(int zoneId, uint64_t playerUin, int platformType, int fromBusId, int transId);
    int SendRoleList(int fromBusId, int transId);
public:
    int TryCreateRole(const proto_ff::Proto_Zone2OnLineCreateRoleReq& req, int fromBusId, int transId);
    int SyncLogin(int logicSvrId, const proto_ff::RoleOne& roleOne, bool isRegister);
    int ClearOnlineData(int logicSvrId, uint64_t roleId);
    bool IsInLockTime();
    bool HasRoleOnline();
public:
    int BroadCast(int msgId, const google::protobuf::Message& xData);
public:
    NFBagPage* GetBagPage() { return &m_stPageStorage; }
private:
    uint64_t m_uid;
    int m_zoneId;
    NFShmString<MAX_PLAYER_ACCOUNT_SIZE> m_account;
    int  m_state;
    bool m_isInitRoleList;
    int m_loginTransTime;
    int m_addRoleLockTime;
private:
    NFBagPageImpl<MAX_GRID_OF_STORAGE> m_stPageStorage;
};
